#pragma once

#include "comm/znx_pool.h"
#include "comm/znx_array.h"
#include "comm/znx_string.h"
#include "comm/znx_module.h"
#include "comm/znx_log.h"
#include "comm/znx_inet.h"


typedef struct {
    znx_bool_t                  ignore_invalid_headers;

    size_t                      request_header_buf_size;
    size_t                      max_request_header_size;
    size_t                      request_body_buf_size;
    size_t                      max_read_request_body_size_limit;
    int64_t                     read_request_header_timeout_ms;
    int64_t                     read_request_body_timeout_ms;
    int64_t                     write_response_body_timeout_ms;

    size_t                      response_header_buf_size;
    size_t                      max_response_header_size;
    size_t                      response_body_buf_size;
    size_t                      max_read_response_body_size_limit;
    int64_t                     read_response_header_timeout_ms;
    int64_t                     read_response_body_timeout_ms;
    int64_t                     write_request_body_timeout_ms;

    int64_t                     server_conn_idle_timeout_ms;
} znx_http_core_conf_t;


typedef struct {
    int                         lookup_depth;
    znx_http_core_conf_t        *server_core_conf;
    znx_http_core_conf_t        *proxy_core_conf;

    void                        **modules;
    znx_pool_t                  *pool;
    znx_str_t                   err;
} znx_http_main_conf_t;


extern znx_http_main_conf_t     *g_http_main_conf;
extern znx_command_t            znx_http_core_commands[];


znx_http_core_conf_t *znx_http_core_conf_create(znx_pool_t *pool);
znx_bool_t znx_http_core_conf_check_and_fix(znx_http_core_conf_t *core_conf);
znx_bool_t znx_http_core_conf_merger_and_fix(znx_http_core_conf_t *core_conf,
    znx_http_core_conf_t *pre_core_conf);


// when parsing fails, if http_main_conf exists,
// we will set err msg into http_main_conf->err
znx_bool_t znx_http_main_conf_parse(const char *filepath);

void znx_http_main_destroy();


#define znx_http_get_main_module_conf(module)               \
    g_http_main_conf->modules[module.index]

#define znx_http_set_main_module_conf(module, module_conf)  \
    g_http_main_conf->modules[module.index] = module_conf

